const http = uni.$u.http
import {
	baseUrl
} from '@/utils/config.js'

const api = {
	submit: '/appointment/submit',
	edit: '/appointment/edit',
	list: '/appointment/list',
	detail: '/appointment/detail',
	cancel: '/appointment/cancel',
	code: '/appointment/code',
	checkin: '/appointment/checkin',
	setting: '/appointment/setting',
	uploadImage: '/appointment/uploadImage',
	deleteFile: '/appointment/deleteFile',
}

// 提交预约
export const submit = (params, config) => http.post(api.submit, params, config)
// 签到
export const checkin = (params, config) => http.post(api.checkin, params, {
	custom: {
		toast: false,
		catch: true
	},
	...config
})
// 修改预约
export const edit = (params, config) => http.post(api.edit, params, config)

// 预约列表
export const list = (params) => http.get(api.list, {
	custom: {
		toast: false
	},
	...params
})

// 预约详情
export const detail = (params) => http.get(api.detail, {
	custom: {
		toast: false,
		catch: true
	},
	...params
})

// 取消预约
export const cancel = (params) => http.get(api.cancel, {
	custom: {
		toast: false,
		catch: true
	},
	...params
})

// 预约设置
export const setting = (params) => http.get(api.setting, {
	custom: {
		toast: false,
	},
	...params
})

// export const code = (params) => http.get(api.code, {
// 	custom: {
// 		toast: false,
// 	},
// 	dataType: 'text',
// 	responseType: 'arraybuffer',
// 	...params
// })

export const code = (data) => {
	return new Promise((resolve, reject) => {
		uni.showLoading({
			title: '正在加载',
			mask: true
		})

		uni.request({
			url: baseUrl + api.code,
			data,
			responseType: 'arraybuffer',
			success: res => {
				resolve(res)
			},
			complete: () => {
				uni.hideLoading()
			}
		})
	})
}


export const uploadImage = (config = {}) => http.upload(api.uploadImage, {
	custom: {
		toast: false,
		catch: true
	},
	...config
})

export const deleteFile = (params, config = {}) => http.post(api.deleteFile, params, {
	custom: {
		toast: false
	},
	...config
})